<?php

namespace App\Http\Controllers\Admin;

use App\Carousel;
use App\Http\Response;
use App\Services\WechatService;
use App\Store;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class StoreController extends Controller
{
    use Response;


    /**
     * CarouselController constructor.
     * @param $mch_id
     */

    public function index(Request $request)
    {
        $paginate=Store::paginate($request->get('pageSize'),'*','pageNo');

        return $this->success(200,$paginate);

    }
    public function show($id)
    {
        $result=Store::find($id);
        return $this->success(200,$result);
    }
    public function store(Request $request)
    {
        $create=Store::create($request->all());
        $service=new WechatService();
        $file_name=$service->getUnlimit($create->id.".9.","pages/product/product",['width'=>600]);
        $create->qrcode=$file_name;
        $create->save();
        if ($create){
            return $this->message(200,'新增成功');
        }else{
            return $this->error(505,'新增失败');
        }
    }
    public function update($id,Request $request)
    {
        $update=Store::where('id',$id)->update($request->all());
        if ($update){
            return $this->message(200,'更新成功');
        }else{
            return $this->error(505,'更新失败');
        }

    }

    public function destroy($carousel)
    {
        $delete=Store::destroy($carousel);

        if ($delete){
            return $this->message(200,'删除成功');
        }else{
            return $this->error(505,'删除失败');
        }

    }
}
